import {observable, action, computed, toJS} from 'mobx';
import { Tools } from 'weaver-mobile';
import objectAssign from "object-assign";
import {ListAdvanced} from 'weaver-mobile-page';
import * as API from '../../apis/adjustLog/AdjustLogApi';

export default class AdjustLogStore {
    @observable listAd = new ListAdvanced.Store();

    routepath = "/odocComs";
    dataParams = {
        dataUrl: "/api/odoc/adjustLog/loadDatas",
        contionUrl: "/api/odoc/adjustLog/loadConfig",
        params:{
            type:this.type,
        },
    }

    /**
     * init
     * @param prepath
     * @param commonParam
     */
    init = (prepath, commonParam={}) => {
        const {requestid, nodeid, workflowid, formid} = commonParam;
        let {params} = this.dataParams;
        // params = {...params,requestid, nodeid, workflowid, formid, ...{requestid:10662660, nodeid:42530, workflowid:51022}};
        params = {...params,...commonParam};
        this.dataParams = {...this.dataParams, params};
        this.routepath = prepath;
        this.listAd = new ListAdvanced.Store({route: this.routepath, id: "adjustlog"});
        this.getData()
    }


    /**
     * 初始化
     * @param params
     * @returns {Promise<void>}
     */
    @action
    getData = (pparams = {}) => {
        const {dataUrl,params} = this.dataParams;
        const {searchAdvancedStore, listViewStore, searchParams } = this.listAd;
        let sparams = { ...searchParams };
        // 获取高级搜索参数
        if (searchAdvancedStore) {
            const { formParams } = searchAdvancedStore.form;
            sparams = { ...formParams };
        }
        listViewStore.selectNone();
        listViewStore.clearData();
        pparams.params = {...pparams.params, ...params, ...sparams};

        this.listAd && this.listAd.getData({
            url: dataUrl,
            method: "POST",
            ...pparams,

        },(res)=>{
            const {requestid,workflowid} = res;
            this.coreparams = {requestid, workflowid};
        })
    }
}